/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Main.java
 *
 * Created on Dec 17, 2011, 3:11:21 PM
 */
package GUI;

import DAL.DataAccess;
import Entities.Staff;
import java.awt.CardLayout;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author MarsX
 */
public class Main extends javax.swing.JFrame {

    public boolean flags = false;
    private Staff staff = null;
    private ICentralPanel centralPanel = null;
    int i = 1;

    /** Creates new form Main */
    public Main() {
        initComponents();
        CardLayout layout = (CardLayout) pLoginCardLayout.getLayout();
        layout.show(pLoginCardLayout, "LoginForm");
        jMenuAdmin.setEnabled(false);
        jMenuStaff.setEnabled(false);
        jMenuClient.setEnabled(false);
        Program p = new Program(staff);
        centralPanel = p;
        pCenter.removeAll();
        p.setSize(pCenter.getSize());
        pCenter.add(p);
        pCenter.revalidate();
        pCenter.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("PrimePhysiquePU", DAL.DataAccess.getConnectionProperties()).createEntityManager();
        jToolBar = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        pWarper = new javax.swing.JPanel();
        pCenter = new javax.swing.JPanel();
        pNewEvent = new javax.swing.JPanel();
        jButtonFunny = new javax.swing.JButton();
        pLoginCardLayout = new javax.swing.JPanel();
        pLogin = new javax.swing.JPanel();
        butLogin = new javax.swing.JButton();
        butReset = new javax.swing.JButton();
        txtPassword = new javax.swing.JPasswordField();
        txtUserName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        pLoginSuccess = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtStaffName = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        btnExit = new javax.swing.JButton();
        jButtonChangePass = new javax.swing.JButton();
        jButtonChangeDetails = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        jButton2 = new javax.swing.JButton();
        jToolBar2 = new javax.swing.JToolBar();
        jButton3 = new javax.swing.JButton();
        jToolBar3 = new javax.swing.JToolBar();
        jButton4 = new javax.swing.JButton();
        jToolBar4 = new javax.swing.JToolBar();
        jButton5 = new javax.swing.JButton();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuDatabaseConfig = new javax.swing.JMenuItem();
        jMenuExit = new javax.swing.JMenuItem();
        jMenuView = new javax.swing.JMenu();
        jMenuProgram = new javax.swing.JMenuItem();
        jMenuNutrition = new javax.swing.JMenuItem();
        jMenuNews = new javax.swing.JMenuItem();
        jMenuStory = new javax.swing.JMenuItem();
        jMenuAdmin = new javax.swing.JMenu();
        jMenuStaff = new javax.swing.JMenuItem();
        jMenuClient = new javax.swing.JMenuItem();
        jMenuAbout = new javax.swing.JMenu();
        jMenuBranches = new javax.swing.JMenuItem();
        jMenuAboutUs = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Prime Physicque");
        setMinimumSize(new java.awt.Dimension(984, 576));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jToolBar.setRollover(true);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/diet-fitness-icon.png"))); // NOI18N
        jButton1.setText("Fitness Program");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuProgramActionPerformed(evt);
            }
        });
        jToolBar.add(jButton1);

        pWarper.setPreferredSize(new java.awt.Dimension(1000, 550));

        pCenter.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pCenter.setMinimumSize(new java.awt.Dimension(638, 502));
        pCenter.setPreferredSize(new java.awt.Dimension(638, 502));

        javax.swing.GroupLayout pCenterLayout = new javax.swing.GroupLayout(pCenter);
        pCenter.setLayout(pCenterLayout);
        pCenterLayout.setHorizontalGroup(
            pCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 741, Short.MAX_VALUE)
        );
        pCenterLayout.setVerticalGroup(
            pCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 531, Short.MAX_VALUE)
        );

        pNewEvent.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pNewEvent.setMinimumSize(new java.awt.Dimension(310, 160));
        pNewEvent.setPreferredSize(new java.awt.Dimension(310, 160));

        jButtonFunny.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/funny1.gif"))); // NOI18N
        jButtonFunny.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFunnyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pNewEventLayout = new javax.swing.GroupLayout(pNewEvent);
        pNewEvent.setLayout(pNewEventLayout);
        pNewEventLayout.setHorizontalGroup(
            pNewEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jButtonFunny, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
        );
        pNewEventLayout.setVerticalGroup(
            pNewEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jButtonFunny, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
        );

        pLoginCardLayout.setLayout(new java.awt.CardLayout());

        pLogin.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Login Employees", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), java.awt.Color.blue)); // NOI18N
        pLogin.setMinimumSize(new java.awt.Dimension(310, 160));
        pLogin.setPreferredSize(new java.awt.Dimension(310, 160));

        butLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/Login.png"))); // NOI18N
        butLogin.setText("Login");
        butLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butLoginActionPerformed(evt);
            }
        });

        butReset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/reset1.png"))); // NOI18N
        butReset.setText("Reset");
        butReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butResetActionPerformed(evt);
            }
        });

        txtPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butLoginActionPerformed(evt);
            }
        });

        txtUserName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butLoginActionPerformed(evt);
            }
        });

        jLabel1.setText("UserName : ");

        jLabel2.setText("Password : ");

        javax.swing.GroupLayout pLoginLayout = new javax.swing.GroupLayout(pLogin);
        pLogin.setLayout(pLoginLayout);
        pLoginLayout.setHorizontalGroup(
            pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLoginLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pLoginLayout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addGap(31, 31, 31)
                            .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pLoginLayout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(28, 28, 28)
                            .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pLoginLayout.createSequentialGroup()
                        .addComponent(butLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(butReset)))
                .addGap(39, 39, 39))
        );
        pLoginLayout.setVerticalGroup(
            pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLoginLayout.createSequentialGroup()
                .addGroup(pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pLoginLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel1))
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pLoginLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel2))
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(butReset, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(butLogin, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addGap(48, 48, 48))
        );

        pLoginCardLayout.add(pLogin, "LoginForm");

        pLoginSuccess.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "User Manager", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), java.awt.Color.blue)); // NOI18N

        jLabel3.setText("Hello : ");

        txtStaffName.setText("strUser");

        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/logout.png"))); // NOI18N
        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        jButtonChangePass.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/changepass.png"))); // NOI18N
        jButtonChangePass.setText("Change Password");
        jButtonChangePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonChangePassActionPerformed(evt);
            }
        });

        jButtonChangeDetails.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/Info.png"))); // NOI18N
        jButtonChangeDetails.setText("Change Details");
        jButtonChangeDetails.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonChangeDetailsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pLoginSuccessLayout = new javax.swing.GroupLayout(pLoginSuccess);
        pLoginSuccess.setLayout(pLoginSuccessLayout);
        pLoginSuccessLayout.setHorizontalGroup(
            pLoginSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pLoginSuccessLayout.createSequentialGroup()
                .addContainerGap(215, Short.MAX_VALUE)
                .addComponent(btnExit)
                .addContainerGap())
            .addGroup(pLoginSuccessLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(44, 44, 44)
                .addComponent(txtStaffName)
                .addContainerGap(182, Short.MAX_VALUE))
            .addGroup(pLoginSuccessLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pLoginSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButtonChangeDetails, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonChangePass, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(149, Short.MAX_VALUE))
        );
        pLoginSuccessLayout.setVerticalGroup(
            pLoginSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pLoginSuccessLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pLoginSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(txtStaffName, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonChangePass)
                .addGroup(pLoginSuccessLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pLoginSuccessLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(btnExit))
                    .addGroup(pLoginSuccessLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonChangeDetails)))
                .addContainerGap())
        );

        pLoginCardLayout.add(pLoginSuccess, "LoginSuccess");

        javax.swing.GroupLayout pWarperLayout = new javax.swing.GroupLayout(pWarper);
        pWarper.setLayout(pWarperLayout);
        pWarperLayout.setHorizontalGroup(
            pWarperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pWarperLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pCenter, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pWarperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pLoginCardLayout, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                    .addComponent(pNewEvent, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
                .addContainerGap())
        );
        pWarperLayout.setVerticalGroup(
            pWarperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pWarperLayout.createSequentialGroup()
                .addGroup(pWarperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pCenter, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE)
                    .addGroup(pWarperLayout.createSequentialGroup()
                        .addComponent(pLoginCardLayout, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pNewEvent, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jToolBar1.setRollover(true);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/Food_1.png"))); // NOI18N
        jButton2.setText("Nutrition Zone");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNutritionActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jToolBar2.setRollover(true);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/star.png"))); // NOI18N
        jButton3.setText("News and Event");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewsActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton3);

        jToolBar3.setRollover(true);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/story.png"))); // NOI18N
        jButton4.setText("Success Story");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuStoryActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton4);

        jToolBar4.setRollover(true);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/house.png"))); // NOI18N
        jButton5.setText("Branches");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuBranchesActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton5);

        jMenuFile.setText("File");

        jMenuDatabaseConfig.setText("Database Config");
        jMenuDatabaseConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuDatabaseConfigActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuDatabaseConfig);

        jMenuExit.setText("Exit");
        jMenuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuExitActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuExit);

        jMenuBar.add(jMenuFile);

        jMenuView.setText("View");

        jMenuProgram.setText("Fitness Program");
        jMenuProgram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuProgramActionPerformed(evt);
            }
        });
        jMenuView.add(jMenuProgram);

        jMenuNutrition.setText("Nutrition Zone");
        jMenuNutrition.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNutritionActionPerformed(evt);
            }
        });
        jMenuView.add(jMenuNutrition);

        jMenuNews.setText("News and Event");
        jMenuNews.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewsActionPerformed(evt);
            }
        });
        jMenuView.add(jMenuNews);

        jMenuStory.setText("Success Story");
        jMenuStory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuStoryActionPerformed(evt);
            }
        });
        jMenuView.add(jMenuStory);

        jMenuBar.add(jMenuView);

        jMenuAdmin.setText("Admin");

        jMenuStaff.setText("Staff Manager");
        jMenuStaff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuStaffActionPerformed(evt);
            }
        });
        jMenuAdmin.add(jMenuStaff);

        jMenuClient.setText("Client Manager");
        jMenuClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuClientActionPerformed(evt);
            }
        });
        jMenuAdmin.add(jMenuClient);

        jMenuBar.add(jMenuAdmin);

        jMenuAbout.setText("About");

        jMenuBranches.setText("Branches");
        jMenuBranches.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuBranchesActionPerformed(evt);
            }
        });
        jMenuAbout.add(jMenuBranches);

        jMenuAboutUs.setText("About Us");
        jMenuAboutUs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuAboutUsActionPerformed(evt);
            }
        });
        jMenuAbout.add(jMenuAboutUs);

        jMenuBar.add(jMenuAbout);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(519, Short.MAX_VALUE))
            .addComponent(pWarper, javax.swing.GroupLayout.DEFAULT_SIZE, 1095, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pWarper, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuDatabaseConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuDatabaseConfigActionPerformed
    // TODO add your handling code here:
    MainDatabaseConfigDialog dialog = new MainDatabaseConfigDialog(this, false);
    dialog.show();
}//GEN-LAST:event_jMenuDatabaseConfigActionPerformed

private void butLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butLoginActionPerformed
// TODO add your handling code here:
    if (txtUserName.getText().trim().compareTo(" ") == 0 || txtUserName.getText().equals("")) {
        JOptionPane.showMessageDialog(null, "Input User Name", "Message", JOptionPane.ERROR_MESSAGE);
        txtUserName.setBackground(new java.awt.Color(204, 204, 255));
        txtUserName.requestFocus();
    } else if (txtPassword.getText().trim().compareTo(" ") == 0 || txtPassword.getText().equals("")) {
        JOptionPane.showMessageDialog(null, "Input Password", "Message", JOptionPane.ERROR_MESSAGE);
        txtPassword.setBackground(new java.awt.Color(204, 204, 255));
        txtPassword.setBackground(new java.awt.Color(255, 255, 255));
        txtPassword.requestFocus();
    } else {
        txtPassword.setBackground(new java.awt.Color(255, 255, 255));
        txtUserName.setBackground(new java.awt.Color(255, 255, 255));
        String username = txtUserName.getText();
        String password = String.copyValueOf(txtPassword.getPassword());
        try {
            Query q = entityManager.createQuery("SELECT s FROM Staff s WHERE s.staUserName = :staUserName AND s.staPassword = :staPassword").setParameter("staUserName", username.toLowerCase()).setParameter("staPassword", password);
            staff = (Staff) q.getSingleResult();
            if (staff != null) {
                if (centralPanel != null) {
                    centralPanel.setStaff(staff);
                }
                jMenuAdmin.setEnabled(true);
                jMenuClient.setEnabled(true);
                jMenuStaff.setEnabled(staff.isAdmin());
                CardLayout layout = (CardLayout) pLoginCardLayout.getLayout();
                layout.show(pLoginCardLayout, "LoginSuccess");
                txtStaffName.setText(username);
            } else {
                JOptionPane.showMessageDialog(this, "Incorrect username or password");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Incorrect username or password");
        }
    }
}//GEN-LAST:event_butLoginActionPerformed

private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
    txtUserName.setText("");
    txtPassword.setText("");
    staff = null;
    CardLayout layout = (CardLayout) pLoginCardLayout.getLayout();
    layout.show(pLoginCardLayout, "LoginForm");
    if (centralPanel != null) {
        centralPanel.setStaff(staff);
    }
    jMenuAdmin.setEnabled(false);
    jMenuStaff.setEnabled(false);
    jMenuClient.setEnabled(false);
}//GEN-LAST:event_btnExitActionPerformed

private void jMenuProgramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuProgramActionPerformed
    Program p = new Program(staff);
    centralPanel = p;
    pCenter.removeAll();
    p.setSize(pCenter.getSize());
    pCenter.add(p);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuProgramActionPerformed

private void jMenuNutritionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNutritionActionPerformed
    NutritionZone n = new NutritionZone(staff);
    centralPanel = n;
    pCenter.removeAll();
    n.setSize(pCenter.getSize());
    pCenter.add(n);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuNutritionActionPerformed

private void jMenuNewsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewsActionPerformed
    NewsAndEvent ne = new NewsAndEvent(staff);
    centralPanel = ne;
    pCenter.removeAll();
    ne.setSize(pCenter.getSize());
    pCenter.add(ne);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuNewsActionPerformed

private void jMenuStoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuStoryActionPerformed
    SuccessStory ss = new SuccessStory(staff);
    centralPanel = ss;
    pCenter.removeAll();
    ss.setSize(pCenter.getSize());
    pCenter.add(ss);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuStoryActionPerformed

private void jMenuBranchesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuBranchesActionPerformed
    Branches br = new Branches(staff);
    centralPanel = br;
    pCenter.removeAll();
    br.setSize(pCenter.getSize());
    pCenter.add(br);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuBranchesActionPerformed

private void jMenuAboutUsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuAboutUsActionPerformed
    AboutUs us = new AboutUs(this, true);
    us.setVisible(true);
}//GEN-LAST:event_jMenuAboutUsActionPerformed

private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuExitActionPerformed
    dispose();
    System.exit(0);
}//GEN-LAST:event_jMenuExitActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    dispose();
    System.exit(0);
}//GEN-LAST:event_formWindowClosing

private void jMenuStaffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuStaffActionPerformed
    GUI.Staff s = new GUI.Staff(staff);
    centralPanel = s;
    pCenter.removeAll();
    s.setSize(pCenter.getSize());
    pCenter.add(s);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuStaffActionPerformed

private void jMenuClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuClientActionPerformed
    Client c = new Client(staff);
    centralPanel = c;
    pCenter.removeAll();
    c.setSize(pCenter.getSize());
    pCenter.add(c);
    pCenter.revalidate();
    pCenter.repaint();
}//GEN-LAST:event_jMenuClientActionPerformed

private void jButtonFunnyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFunnyActionPerformed
    if (i < 4 && i > 0) {
        i++;
    } else {
        i = 1;
    }
    jButtonFunny.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/funny" + i + ".gif")));
}//GEN-LAST:event_jButtonFunnyActionPerformed

private void butResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butResetActionPerformed
    txtUserName.setText("");
    txtPassword.setText("");
}//GEN-LAST:event_butResetActionPerformed

private void jButtonChangePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChangePassActionPerformed
    StaffChangePasswordDialog cpd = new StaffChangePasswordDialog(this, true, staff);
    cpd.setVisible(true);
    if (cpd.getReturnStatus() == 1) {
        try {
            staff = cpd.getStaff();
            entityManager.getTransaction().begin();
            entityManager.merge(staff);
            entityManager.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_jButtonChangePassActionPerformed

private void jButtonChangeDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChangeDetailsActionPerformed
    StaffChangeUserDetailsDialog cpd = new StaffChangeUserDetailsDialog(this, true, staff);
    cpd.setVisible(true);
    if (cpd.getReturnStatus() == 1) {
        try {
            staff = cpd.getStaff();
            entityManager.getTransaction().begin();
            entityManager.merge(staff);
            entityManager.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_jButtonChangeDetailsActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    DataAccess.testDefaultConnection();
                } catch (ClassNotFoundException ex) {
                    JOptionPane.showMessageDialog(null, "Library sqljdbc4 not found", "Prime Physique", JOptionPane.ERROR_MESSAGE);
                    System.exit(0);
                    return;
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, "Please Config your databse connection", "Prime Physique", JOptionPane.ERROR_MESSAGE);
                    MainDatabaseConfigDialog dcd = new MainDatabaseConfigDialog(null, true);
                    dcd.setVisible(true);
                    if (dcd.getReturnStatus() == 0) {
                        System.exit(0);
                        return;
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Please Config your databse connection", "Prime Physique", JOptionPane.ERROR_MESSAGE);
                    MainDatabaseConfigDialog dcd = new MainDatabaseConfigDialog(null, true);
                    dcd.setVisible(true);
                    if (dcd.getReturnStatus() == 0) {
                        System.exit(0);
                        return;
                    }
                }

                new Main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExit;
    private javax.swing.JButton butLogin;
    private javax.swing.JButton butReset;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButtonChangeDetails;
    private javax.swing.JButton jButtonChangePass;
    private javax.swing.JButton jButtonFunny;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenuAbout;
    private javax.swing.JMenuItem jMenuAboutUs;
    private javax.swing.JMenu jMenuAdmin;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuItem jMenuBranches;
    private javax.swing.JMenuItem jMenuClient;
    private javax.swing.JMenuItem jMenuDatabaseConfig;
    private javax.swing.JMenuItem jMenuExit;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuNews;
    private javax.swing.JMenuItem jMenuNutrition;
    private javax.swing.JMenuItem jMenuProgram;
    private javax.swing.JMenuItem jMenuStaff;
    private javax.swing.JMenuItem jMenuStory;
    private javax.swing.JMenu jMenuView;
    private javax.swing.JToolBar jToolBar;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JPanel pCenter;
    private javax.swing.JPanel pLogin;
    private javax.swing.JPanel pLoginCardLayout;
    private javax.swing.JPanel pLoginSuccess;
    private javax.swing.JPanel pNewEvent;
    private javax.swing.JPanel pWarper;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JLabel txtStaffName;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
}
